namespace('is.theme', new function(){

    var DEFAULT  = 'mario';
    var CSS_ROOT = '/css/theme';

    // Load a css file from its path and media specification
    this.load_css = function(path, media) {
        media = (typeof(meda) != 'undefined') ? media : 'screen, projection';
        $('head').append('<link class="theme" rel="stylesheet" type="text/css" href="' +
                         path + '" media="' + media + '" />');
    };

    // Remove all css files associated with themes
    this.reset_theme = function() {
        $('link.theme').each(function(){ $(this).remove(); });
    };

    // Load theme files by name
    this.load = function(name, callback) {
        var path = CSS_ROOT + '/' + name + '/';
        callback = (typeof(callback) == 'undefined') ? function(){} : callback;

        // Remove any exisiting theme files
        this.reset_theme();

        // Load the theme and its ui style
        this.load_css(path + 'style.css');
        this.load_css(path + 'style.ui.css');

        // Load the theme javascript
        $.getScript(path + 'style.js', callback);
    }

    // Load a default theme
    this.init = function() {
        // Load the default theme
        is.theme.load(DEFAULT);
    }

    is.register('init', this);

});
